#include "Graph.h"

void Graph::printGraph(std::ostream &stream)
{
	for(int i=0; i<n; ++i)
		for(int j=0; j<n; ++j)
			if(matrix[i*n+j].soil>0.0)
				stream<<"["<<i<<", "<<j<<"] "<<matrix[i*n+j].soil<<"\n";
}


void Graph::readGraph(std::istream &stream)
{
	stream>>n;
	matrix = new edge[n*n];
	memset(matrix, -1 , n*n*sizeof(edge));
	while(!stream.eof())
	{
		int i, j;
		double soil;
		stream>>i>>j;
		matrix[i*n+j].soil = InitSoil;
	}
}

Graph::~Graph()
{
	delete []matrix;
}

void Graph::makeGraph()
{
	int n = nodes.size(), e = edges.size();
	matrix = new edge[n * n];
	memset(matrix, -1, n * n * sizeof(edge));
	for(int i=0; i < e; ++i)
	{
		matrix[n * edges[i]->i + edges[i]->j].soil = InitSoil-edges[i]->score;
	}
}

std::vector<Service *> &Graph::getServiceNodes()
{
	return nodes;
}
